package com.bifrost.util;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.ServletWebRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author joewee
 * @version 1.0.0
 * @Date 2017/10/21 20:27
 */
public class HttpContextUtils {

    public static HttpServletRequest getHttpServletRequest() {
        RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
        if (attributes != null) {
            return ((ServletRequestAttributes) attributes).getRequest();
        }
        return null;
    }

    public static HttpServletResponse getHttpServletResponse() {
        RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
        if (attributes != null) {
            return ((ServletRequestAttributes) attributes).getResponse();
        }
        return null;
    }
}
